package net.anzhuo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.common.enums.ResultEnum;
import net.anzhuo.common.utils.ExceptionUtil;
import net.anzhuo.dao.GsCompanyTaxCreditMapper;
import net.anzhuo.entity.GsCompanyTaxCredit;
import net.anzhuo.service.GsCompanyTaxCreditService;
@Service
public class GsCompanyTaxCreditServiceImpl implements GsCompanyTaxCreditService {

	@Autowired
	private GsCompanyTaxCreditMapper gsCompanyTaxCreditMapper;
	
	@Override
	public GsCompanyTaxCredit getById(Long id) {
		// TODO Auto-generated method stub
		
		return gsCompanyTaxCreditMapper.getById(id);
	}

	@Override
	public List<GsCompanyTaxCredit> getBycoMd5(String coMd5) {
		// TODO Auto-generated method stub
		return gsCompanyTaxCreditMapper.getBycoMd5(coMd5);
	}

	@Override
	public PaginationVO<GsCompanyTaxCredit> getListWithPage(GsCompanyTaxCredit gsCompanyTaxCredit) {
		PaginationVO<GsCompanyTaxCredit> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsCompanyTaxCreditMapper.getListWithPage(gsCompanyTaxCredit));
		paginationVO.setTotalCount(gsCompanyTaxCreditMapper.getCount(gsCompanyTaxCredit));
		paginationVO.setTotalPage((gsCompanyTaxCreditMapper.getCount(gsCompanyTaxCredit) + gsCompanyTaxCredit.getPageSize() -1)  / gsCompanyTaxCredit.getPageSize());
		paginationVO.setPageNo(gsCompanyTaxCredit.getPageNo());
		return paginationVO;
	}

	@Override
	public List<GsCompanyTaxCredit> getList() {
		// TODO Auto-generated method stub
		return  gsCompanyTaxCreditMapper.getList();
	}

	@Override
	public List<GsCompanyTaxCredit> getList(GsCompanyTaxCredit gsCompanyTaxCredit) {
		// TODO Auto-generated method stub
		return gsCompanyTaxCreditMapper.getListByQuery(gsCompanyTaxCredit);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsCompanyTaxCredit gsCompanyTaxCredit) {
		// TODO Auto-generated method stub
		gsCompanyTaxCreditMapper.update(gsCompanyTaxCredit);

	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsCompanyTaxCredit gsCompanyTaxCredit) {
		// TODO Auto-generated method stub
		gsCompanyTaxCreditMapper.save(gsCompanyTaxCredit);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(Long id) {
		GsCompanyTaxCredit gsCompanyTaxCredit = gsCompanyTaxCreditMapper.getById(id);
		if (gsCompanyTaxCredit == null) {
			ExceptionUtil.throwAppException(ResultEnum.ILLEGAL_OPERATION);
			return;
		}
		gsCompanyTaxCreditMapper.update(gsCompanyTaxCredit);

	}

}
